package com.yundasys.lab02springbootstudy.boot;

import org.springframework.boot.DefaultBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.EventPublishingRunListener;
import org.springframework.boot.env.EnvironmentPostProcessorApplicationListener;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;

import java.io.IOException;

/**
 * @author jiangta
 * @version 1.0
 * @date 2022/4/1 2:48 下午
 */
public class Step5 {

    public static void main(String[] args) throws IOException {
        SpringApplication app = new SpringApplication();
        app.addListeners(new EnvironmentPostProcessorApplicationListener());


//        List<String> names = SpringFactoriesLoader.loadFactoryNames(EnvironmentPostProcessor.class, Step5.class.getClassLoader());
//        for(String name : names) {
//            System.out.println(name);
//        }

        EventPublishingRunListener publisher = new EventPublishingRunListener(app,args);
        StandardEnvironment environment = new StandardEnvironment();
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>增强前");
        for (PropertySource ps :environment.getPropertySources()) {
            System.out.println(ps);
        }
        publisher.environmentPrepared(new DefaultBootstrapContext(),environment);

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>增强后");
        for (PropertySource ps :environment.getPropertySources()) {
            System.out.println(ps);
        }
    }
}
